import logging
import os


class Logger:
    def __init__(self, log_file_path="training.log"):
        self.logger = logging.getLogger(f"MT_Log")
        self.logger.setLevel(logging.DEBUG)

        # 防止重复添加 handler
        if not self.logger.hasHandlers():
            file_handler = logging.FileHandler(log_file_path, mode="a", encoding="utf-8")
            file_handler.setLevel(logging.DEBUG)

            console_handler = logging.StreamHandler()
            console_handler.setLevel(logging.DEBUG)

            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            file_handler.setFormatter(formatter)
            console_handler.setFormatter(formatter)

            self.logger.addHandler(file_handler)
            self.logger.addHandler(console_handler)

    def get_logger(self):
        return self.logger
